package com.zmn.mcc.services.impl.staff.staffchangelog;

import com.zmn.mcc.model.entity.staff.staffchangelog.StaffChangeLog;
import com.zmn.mcc.model.entity.staff.staffchangelog.StaffChangeLogQuery;
import com.zmn.mcc.persistence.interfaces.staff.staffchangelog.StaffChangeLogDAO;
import com.zmn.mcc.services.interfaces.staff.staffchangelog.StaffChangeLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 员工异动基础接口实现类
 *
 * @author tanghongjun
 * @since 2020-05-14 11:28:02
 **/
@Slf4j
@Service
public class StaffChangeLogServiceImpl implements StaffChangeLogService {

    private static final String TAG = "员工异动基础服务接口";

    @Resource
    private StaffChangeLogDAO staffChangeLogDao;

    /**
     * 描述: 根据id查询数据
     *
     * @param logId id
     * @author tanghongjun
     * @since 2020-05-14 11:28:02
     **/
    @Override
    public StaffChangeLog findById(Integer logId) {

        if (Objects.isNull(logId)) {
            log.error("[{}],根据id查询数据logId为null", TAG);
            return null;
        }
        return staffChangeLogDao.findById(logId);
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query 查询对象
     * @author tanghongjun
     * @since 2020-05-14 11:28:02
     **/
    @Override
    public List<StaffChangeLog> listPageByQuery(StaffChangeLogQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        int count = countByQuery(query);
        query.setTotalCount(count);
        return staffChangeLogDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author tanghongjun
     * @since 2020-05-14 11:28:02
     **/
    @Override
    public List<StaffChangeLog> listByQuery(StaffChangeLogQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return staffChangeLogDao.listByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query 查询对象
     * @author tanghongjun
     * @since 2020-05-14 11:28:02
     **/
    @Override
    public Integer countByQuery(StaffChangeLogQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return staffChangeLogDao.countByQuery(query);
    }


    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param staffChangeLog 待修改数据
     * @return java.lang.Integer
     * @author tanghongjun
     * @since 2020-05-14 11:28:02
     **/
    @Override
    public Integer updateStaffChangeLogByKey(StaffChangeLog staffChangeLog) {

        if (Objects.isNull(staffChangeLog.getLogId())) {
            log.error("[{}],根据id修改数据,staffChangeLog为null", TAG);
            return null;
        }
        return staffChangeLogDao.updateStaffChangeLogByKey(staffChangeLog);
    }

    /**
     * 描述: 新增数据
     *
     * @param staffChangeLog 待新增数据
     * @return java.lang.Integer 主键key
     * @author tanghongjun
     * @since 2020-05-14 11:28:02
     **/
    @Override
    public Integer insert(StaffChangeLog staffChangeLog) {

        if (Objects.isNull(staffChangeLog)) {
            log.error("[{}],新增数据,staffChangeLog为null", TAG);
            return null;
        }
        return staffChangeLogDao.insert(staffChangeLog);
    }

    /**
     * 描述: 根据主键删除数据
     *
     * @param logId
     * @return: 执行结果码
     * @auther: tanghongjun
     * @since: 2020-05-14 11:28:02
     */
    @Override
    public Integer deleteByKey(Integer logId) {

        if (Objects.isNull(logId)) {
            log.error("[{}],根据id删除数据,logId为null", TAG);
            return null;
        }
        return staffChangeLogDao.deleteByKey(logId);
    }

    @Override
    public void batchInsert(List<StaffChangeLog> list) {
        staffChangeLogDao.batchInsert(list);
    }

}